package com.dhcc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dhcc.SnowflakeIdWorker;
import com.dhcc.entity.SysUsers;
import com.dhcc.mapper.SysUsersMapper;
import com.dhcc.service.SysUsersService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 用户Service实现类
 *
 * @ProjectName Dhcc-Cloud
 * @PackageName com.dhcc.service.impl
 * @Title SysUserServiceImpl
 * @Date 2024/10/11 下午3:41
 * @Author LiuGuoting
 */
@Service
public class SysUsersServiceImpl extends ServiceImpl<SysUsersMapper, SysUsers> implements SysUsersService {
    @Resource
    private SnowflakeIdWorker snowflakeIdWorker;
    @Resource
    private SysUsersMapper sysUserMapper;
    /**
     * 根据用户名查询用户信息
     *
     * @param username 用户名
     * @return SysUser 用户实体
     */
    @Override
    public SysUsers getUserByUsername(String username) {
        return baseMapper.getUserByUsername(username);
    }

    /**
     * 注册用户信息
     *
     * @param user 用户实体
     * @return 插入的行数
     */
    @Override
    public int registerUser(SysUsers user) {
        user.setUserId(snowflakeIdWorker.nextId());
        user.setCreateUser(user.getUserName());
        user.setCreateTime(String.valueOf(Date.from(java.time.Instant.now())));
        user.setUpdateUser(user.getUserName());
        user.setUpdateTime(String.valueOf(Date.from(java.time.Instant.now())));
        user.setDelFlag((byte) 0);
        user.setStatus((byte) 1);
        return baseMapper.registerUser(user);
    }

    @Override
    public SysUsers getUserInfo(String userId) {
        return sysUserMapper.getUserInfo(userId);
    }

    @Override
    public Integer updateUserPositionByUserId(String userId, String positionId) {

        return sysUserMapper.updateUserPositionByUserId(userId,positionId);
    }
}
